﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>new document </title>
        <link rel="stylesheet" href="css\bootstrap.css">
        <script src="js/jquery-1.11.3.js">
        </script>
        <script src="js/bootstrap.js">
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8">
    </head>
    <body>
        <header>
            <nav class="navbar navbar-default" style="margin:auto">
                <div class="container">
                    <ul class="nav nav-tabs">
                        <li>
                            <a href="dcxt.php" class="btn btn-default" type="button" style="border:0px;margin:8px 0">
                                点餐系统
                            </a>
                        </li>
                        <li>
                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="border:0px;margin:8px 0;">
                                订单管理<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="lx">
                                <li>
                                    <a href="list.php">订单列表</a>
                                </li>
                                <li>
                                    <a href="history.php">订单记录</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="border:0px;margin:8px 0;">
                                菜品管理<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="lx">
							
                                <li>
                                    <a href="dishappend.php">添加菜品</a>
                                </li>
                                <li>
                                    <a href="dishlist.php">菜品列表</a>
                                </li>
								 <li>
                                    <a href="dishtype.php">添加菜品类型</a>
                                </li> <li>
                                    <a href="typelist.php">菜品类型列表</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="border:0px;margin:8px 0;">
                                餐桌管理<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="lx">
                                <li>
                                    <a href="appendtable.php">添加餐桌</a>
                                </li>
                                <li>
                                    <a href="tablelist.php">餐桌列表</a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="border:0px;margin:8px 0;">
                                登录管理<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="lx">
                                <li>
                                    <a href="modifier.php">修改登陆信息</a>
                                </li>
                                <li>
                                    <a href="#">退出登录</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>
        </header>
		<div class="container">
			<div class="row" style="width:60%">
				<div class="col-xs-3 paga-left">
				<a href="dishlist.php" class="btn btn-default btn-block">菜品列表</a>
				<a href="dcxt.php" class="btn btn-default btn-block">返回主页</a>
				</div>
				<div class="col-xs-8 panel panel-default">
					<div class="panel-heading">
						 <span class="glyphicon glyphicon-plus">添加菜品</span>
					</div>
					<div class="panel-body">
						<div class="row">
							<form class="form-horizental" method="post">
								<div class="form-group">
									<div class="text-center col-xs-3" style="font-size:x-large">菜名:</div>
									<div class="input-group col-xs-6">
										<input type="text" class="form-control" placeholder="dishname" name="dishname">
									</div>
								</div>
								<div class="form-group">
									<div class="text-center col-xs-3" style="font-size:x-large">价格:</div>
									<div class="input-group col-xs-6">
										<input type="text" class="form-control" placeholder="value" name="value">
									</div>
								</div>
								<div class="form-group">
									<div class="text-center col-xs-3" style="font-size:x-large">类型:</div>
									<div class="but-group col-xs-6" style="padding:0%0%0%0%">
										<select id="lx" data-toggle="dropdown" type="text" class="dropdown-toggle" style="width:100%;height:34px" name="type">	
											<ul class="dropdown-menu" aria-labelledby="lx"
												<?php
													$pdo=new PDO('mysql:dbname=test;charset=utf8','root'); 
													$sel=$pdo->prepare('select * from dishtype');
													$sel->execute(array());
													$d=$sel->fetchAll(PDO::FETCH_NAMED);
													foreach($d as $e){
												?>
													<option> <?php echo $e['dishtype'] ?> </option>
												<?php } ?>				
											</ul>
										</select>
									</div>
								</div>
								<div style="height:48px">&nbsp</div>
								<div class="form-group">
									<div class="text-center col-xs-3" style="font-size:x-large">图片:</div>
										<div class="input-group col-xs-6">
										<input type="file" required="required" name="img" class="form-control"/>
										</div>
								</div>
								<div class="form-group">
									<div class="col-xs-7">&nbsp</div>
									<button type="submit" class="btn btn-primary col-xs-3">添加</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
<?php										
	@$dishname=$_REQUEST['dishname'];
	@$value=$_REQUEST['value'];
	@$type=$_REQUEST['type'];
	@$img=$_REQUEST['img']; 
	$pdo=new PDO('mysql:dbname=test;charset=utf8','root'); 
	$sel=$pdo->prepare('select * from menu');
	$isok=$sel->execute(array());
	$list=$sel->fetchAll(PDO::FETCH_NAMED);
	if($isok){
		if(empty($list)){ exit;}
		foreach($list as $val){
			if($dishname == $val['name'] || $img == $val['url']){
				echo "菜名或图片已存在";
				exit;
				} else {
				$sel1=$pdo->prepare('insert into menu(name,value,url,dishtype) values(:dishname,:value,:url,:dishtype)');
				$isok1=$sel1->execute(array('dishname'=>$dishname,'value'=>$value,'url'=>$img,'dishtype'=>$type));
				if($isok1){ echo "添加成功";exit;}
				}
	}
	} else { echo ""; }
?>
